package com.example.springbatchsample.config;

import cn.hutool.core.collection.CollectionUtil;
import org.springframework.batch.item.*;
import org.springframework.stereotype.Component;

import java.util.Iterator;
import java.util.List;

/**
 * 数据读取
 *
 * @author Yunkai Luo
 * @since 2022/1/28
 **/
@Component
public class MyItemReader implements ItemStreamReader<String> {

    public static final List<String> strList = CollectionUtil.list(true,
            "A", "B", "C");

    public Iterator<String> iterator = null;

    @Override public String read() throws Exception {
        if (null == iterator) {
            iterator = strList.listIterator();
        }
        if (iterator.hasNext()) {
            return iterator.next();
        }
        return null;
    }

    @Override public void open(ExecutionContext executionContext) throws ItemStreamException {

    }

    @Override public void update(ExecutionContext executionContext) throws ItemStreamException {

    }

    @Override public void close() throws ItemStreamException {

    }

}
